package com.IClass;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.IClass.App.R;
import com.IClass.IBlogCommentListAdapter.CommentItemView;
import com.IClass.Server.AppJsonDefine.GenJavaCode.homeblogcomment;
import com.IClass.image.AsynImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class iBlogCommentListAdapter2 extends BaseAdapter {

	public static String TAG = "iHotBlogListAdapter";
	private AsynImageLoader mImageAsynLoader;
	private Context context;                        //运行上下文   
	private List<homeblogcomment> commentlist;    //商品信息集合   
	private LayoutInflater listContainer;           //视图容器   
    private static SimpleDateFormat commenttimeformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	public final class CommentItemView
	{                //自定义控件集合     
         public ImageView userimage;     
         public TextView username;     
         public TextView commenttime;   
         public TextView commenttext;
      
	}   
	public iBlogCommentListAdapter2(Context context, List<homeblogcomment> commentslist) 
	{   
	        this.context = context;            
	        listContainer = LayoutInflater.from(context);   //创建视图容器并设置上下文   
	        this.commentlist = commentslist;   
	        mImageAsynLoader = new AsynImageLoader();
	} 
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return commentlist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return commentlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
	homeblogcomment comment= (homeblogcomment)this.getItem(position);
		
		CommentItemView  commentview = null;
		if (convertView == null) {   
			commentview = new CommentItemView();    
            //获取list_item布局文件的视图   
            convertView = listContainer.inflate(R.layout.iask_blogcommentitem, null);   
            //获取控件对象   

//            map.put("username", m.getValue().username);
//	        map.put("body_data", m.getValue().body_data);
//	        map.put("body_template", m.getValue().body_template);
//	        map.put("image_1", m.getValue().image_1);
//	        map.put("title_data", m.getValue().title_data);
//	        map.put("title_template", m.getValue().title_template);
//	        map.put("userimage", IClassApi.SERVER_HOST + "uc_server/"+ m.getValue().avatarurl);
	        
            commentview.userimage = (ImageView)convertView.findViewById(R.id.userimage);
            commentview.username = (TextView)convertView.findViewById(R.id.commentuername);
            commentview.commenttime = (TextView)convertView.findViewById(R.id.commenttime);
            commentview.commenttext = (TextView)convertView.findViewById(R.id.commenttext);
            
            convertView.setTag(commentview);
            
            commentview.userimage.setTag( IClassApi.SERVER_HOST + "uc_server/"+ comment.avatarurl);
            
		}
		else
		{
			commentview = (CommentItemView)convertView.getTag();   
		}	
		//commentview.username.setTextColor(0);
		//commenttext.setTextColor(0);
		//commentview.commenttime.setTextColor(0);
		commentview.username.setText(comment.author);
		
		commentview.commenttime.setText(commenttimeformat.format(new Date(Long.parseLong(comment.dateline) * 1000)));
		commentview.commenttext.setText(comment.message);
		
		mImageAsynLoader.loadBitmap(commentview.userimage,ImageUtil.getBitmapById(convertView.getContext(), R.drawable.icon_3_n));
		
		
		
		
		return convertView;
	}

}
